package bod.gui.menu.items;

import java.awt.Color;
import java.awt.Graphics;

import bod.Images;

public class Button extends Item {

	public static final int	WIDTH	= 256;
	public static final int	HEIGHT	= 64;
	private boolean			pressed;

	public Button(String name, int x, int y) {
		super(name, x, y, WIDTH, HEIGHT);
		this.pressed = false;
	}

	@Override
	public void draw(Graphics g) {
		g.drawImage(this.pressed ? Images.btnp : Images.btnn, this.x, this.y,
				WIDTH, HEIGHT, null);
		g.setColor(Color.white);
		int tx = this.x + this.width / 2
				- g.getFontMetrics().stringWidth(this.name) / 2
				+ (this.pressed ? 2 : 0);
		int ty = this.y + this.height / 2 + g.getFontMetrics().getAscent() / 2
				+ (this.pressed ? 2 : 0);
		g.drawString(this.name, tx, ty);
	}

	@Override
	public void mousePressed(int x, int y) {
		if (this.contains(x, y)) {
			this.pressed = true;
		} else {
			this.pressed = false;
		}
	}

	@Override
	public void mouseReleased(int x, int y) {
		if (this.pressed && this.listener != null) {
			this.listener.event();
		}
		this.pressed = false;
	}

}